Skip to content

id-core: bounded triple-pattern queries with snapshot cursors - #11977

Merged
dezren39 merged 1 commit into
mainfrom
claude/graph-pattern-query
Nov 19, 2026
Merged

dezren39 merged 1 commit into
mainfrom
claude/graph-pattern-query

Conversation

@dezren39

@dezren39 dezren39 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Refs #10221

Before: there was no way to read the graph by pattern. Anything that wanted "who knows whom" or "what does this record assert" had to walk assertions by hand, with no page limit, no budget and no rule about which graphs the caller may see.

After: graph/query.rs answers conjunctive triple-pattern queries over a fixed snapshot of assertions. Each position is a wildcard, an exact term or a variable, and variables join across patterns. Rows come back in one stable total order with the matched assertions and their source_record provenance. Every page is limited, a request can't raise the operator profile's row ceiling, and running past the step budget fails with BudgetExceeded rather than returning rows that look complete. A pattern naming a graph the caller can't read fails with UnauthorizedGraph; other unreadable graphs are never visited, so they change neither results nor costs. graph/cursor.rs gives opaque cursors bound to the snapshot frontier and the query.

How:

  • Stable order is (graph, subject, predicate, object, assertion id) per pattern, with terms compared by canonical bytes. The snapshot frontier is a BLAKE3 hash over the sorted assertion ids, so arrival order and duplicates don't change it.
  • A cursor is [1, frontier, query digest, rows already returned] in canonical CBOR. Another frontier gives CursorExpired; another query, or bytes that aren't a cursor, give CursorMismatch. The page size may change between pages.
  • Profile::INITIAL is the design's suggested profile (page 100, ceiling 1,000, 1,000,000 steps). Response-byte and CPU ceilings aren't modelled yet; steps bound the work.
  • Oracle is the reference one from the issue: tests/graph_query_reference.rs has an independent matcher (brute-force tuple enumeration, its own term encoding for ordering, its own step count). A property test (512 cases) follows cursors to the end and checks the pages concatenate to exactly the reference rows, only the last page is complete, every page cost matches, and unauthorized or over-budget queries fail. Six fixtures cover a two-hop join with provenance, graph authorization, budget and limits, malformed queries, cursor binding, and frontier stability.
  • Mutation check: 23 hand mutants. Four survived the first run; one exposed a redundant sort (removed) and three exposed missing checks (underscore variable names, the graph in the query digest, the index in the frontier), now covered.
  • Not wired into graph/mod.rs; slice 9110-09 owns that, so the test includes the files by path.

Test: cargo test -p id-core --test graph_query_reference (7 passed); clippy clean on the new files.


Generated by Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Adds graph/query.rs (conjunctive patterns over a fixed snapshot,
stable total order, provenance per row, read policy, page limit and
step budget) and graph/cursor.rs (opaque cursors bound to the frontier
and query). Checked against an independent reference matcher with
cursor-page concatenation.

Refs #10221

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dezren39
dezren39 requested a review from a team as a code owner November 19, 2026 00:36
@dezren39
dezren39 merged commit b0ddaf7 into main Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bfce8bf2-eae3-43c0-9074-33ae83c1c0c0
Commits

Reviewing files that changed from the base of the PR and between 5e74f7d and 5937cc8.

Files selected for processing: 3

  • pkgs/id/crates/id-core/src/graph/cursor.rs
  • pkgs/id/crates/id-core/src/graph/query.rs
  • pkgs/id/crates/id-core/tests/graph_query_reference.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 deleted the claude/graph-pattern-query branch November 19, 2026 00:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T00:38:07.429859Z 5937cc8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants